var Page = function(){
    this.init();
};
Page.prototype = {
    params: {
        passport: '',
        page: 1,
        listRows: 10,
        total: 0,
        state: '',
        orderNumber: '',
        memberInfoName:'',
        order:'desc'
    },
    init: function(){
        this.initParams();
        this.initEvent();
    },
    initParams: function(){
        this.params.passport = Pub.getCookie('_PASSPORT');
    },
     getData: function() {
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport,
            page: _this.params.page,
            listRows: _this.params.listRows,
            state: _this.params.state,
            order: _this.params.order,
            orderNumber: _this.params.orderNumber,
            memberInfoName: _this.params.memberInfoName,
            type:1
        };
        console.log(paramsObj);
        Api.expressorderlist(paramsObj, function(data) {
            console.log(data);
            _this.getDataList(data.list);
            _this.params.total = data.totalPages;
            layui.use('laypage', function() {
                var laypage = layui.laypage;
                //执行一个laypage实例
                laypage.render({
                    elem: 'page',
                    index: 1,
                    theme: '#3498db',
                    curr: _this.params.page,
                    count: _this.params.total, //数据总数，从服务端得到
                    hash: 'curr_page',
                    layout: ['prev', 'page', 'next', 'skip'],
                    jump: function(obj, first) {
                        _this.params.page = obj.curr;
                        //obj包含了当前分页的所有参数，比如：curr当前页
                        var Params = {
                            passport: _this.params.passport,
                            page: _this.params.page,
                            listRows: _this.params.listRows,
                            state: _this.params.state,
                            order: _this.params.order,
                            orderNumber: _this.params.orderNumber,
                            memberInfoName: _this.params.memberInfoName,
                            type:1
                        };
                        Api.expressorderlist(Params, function(data) {
                            _this.getDataList(data.list);

                        })
                    }
                });
            });
        });
    },
    getDataList: function(data) {
        var _this = this;
        if (data && data.length > 0) {
            var html = '',
                i = 0,
                len = data.length;
            for (i; i < len; i++) {
                html += '<tr>' +
                        '<td class="text-c">' + data[i].orderNumber + '</td>' ;
                if (data[i].state==60) {
                    html +='<td class="text-c">派件</td>';
                }else if (data[i].state==65) {
                    html +='<td class="text-c">中转</td>';
                };
                html +='<td class="text-c">' + data[i].memberName + '</td>';


                html += '<td class="text-c">' +
                '<p><a stationOrderId="' + data[i].stationOrderId + '" class="handle view">查看</a><a stationOrderId="' + data[i].stationOrderId + '" class="handle delete">删除</a></p>'
                    '</td>' +
                    '</tr>';
            }
            $('#List').html(html);
            $('tfoot').css('display', 'table-footer-group');
            _this.getDataEvent();
        } else {
            var html = '<tr>' +
                '<td class="text-c c-666" colspan="4" >暂无数据</td>' +
                '</tr>';
            $('#List').html(html);
            $('tfoot').css('display', 'none');
        }
    },
    getDataEvent: function() {
        var _this = this;
        honeySwitch.init();
        $('.view').on('click', function() {
            Pub.setSession('stationOrderId', $(this).attr('stationOrderId'));
            window.location.href = Pub.getHtmlUrl('./stock-out-detail.html');
        });
        $('.delete').on('click', function(event) {
            event.preventDefault();
            var stationOrderId=$(this).attr('stationOrderId');
            layui.use('layer', function(){
                layer.confirm('您确定要删除吗？', {
                    btn: ['确定','取消'] //按钮
                }, function(index){
                    _this.deleteEvent(stationOrderId);
                    layer.close(index);
                }, function(){

                });
            });
        });

    },
    deleteEvent:function(stationOrderId){
        var _this = this;
        var Params = {
            passport: _this.params.passport,
            stationOrderId:stationOrderId
        };
        console.log(Params);
        Api.expressorderlistdel(Params, function(data) {
            _this.params.page=1;
            _this.getData();
        })
    },
    otherEvent:function(){
        var _this = this;
        $('.goods-checkbox input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        })
        $('.slectShow').click(function(event) {
            $('.select-wrap').toggle(400);
        });
        $('#changeSize').on('change', function(event) {
            event.preventDefault();
            _this.params.listRows = $(this).val();
            _this.params.page=1;
            _this.getData();
        });
        $('#changeDesc').on('change', function(event) {
            event.preventDefault();
            if ($(this).val() != 'z') {
                _this.params.order = $(this).val();
                _this.params.page=1;
                _this.getData();
            };
        });
        $('#stateSelect').on('change', function(event) {
            event.preventDefault();
            _this.params.state = $(this).val();
        });
        $('#normalSearch').click(function(event) {
            _this.params.memberInfoName = $('#memberInfoName').val();
            _this.params.orderNumber = $('#orderNumber').val();
            _this.params.page = 1;
            _this.getData();
        });

    },
    initEvent: function(){
        var _this = this;
        _this.getData();
        _this.otherEvent();


    }
};
var page = new Page();